//
//  UINavigationController+UATNavigator.m
//  UStarter
//
//  Created by Mark on 2021/1/8.
//

#import "UINavigationController+UATNavigator.h"

@implementation UINavigationController (UATNavigator)

- (void) pushViewController:(NSString*)vc paramStr:(nullable NSString*)paramStr animated:(BOOL)animated ; {
    Class cls = NSClassFromString(vc);
    if(cls==nil){
        NSLog(@"cls is nil, check %@",vc);
        return ;
    }
    id instance = [cls new];
  
    NSDictionary * dic = [UatUtil convertUrlStrToDictionary:paramStr];
    
    [[dic allKeys] enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        // 存在该属性才赋值
        if([UatUtil checkIsExistPropertyWithInstance:instance verifyPropertyName:obj]){
            [instance setValue:[dic objectForKey:obj] forKey:obj];
        }
    }];
    
    [self pushViewController:instance animated:animated];
    
}

- (void) resetViewController:(UIViewController *)vc animated:(BOOL)animated {
    [self setViewControllers:@[vc] animated:animated];
}

@end
